package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.annotations.Where;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.Part;
import com.mes.basicdata.domain.TypesData;
import com.mes.basicdata.domain.WorkCenter;
import com.mes.common.domain.BasicModel;

@Entity()
@Table(name = "T_ASSIGNMENTS")
@Where(clause = "assntype = 2")
@BatchSize(size = 20)
@Lazy(value = true)
public class TaskResource extends BasicModel {

	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUEID", unique = true)
	protected String uniqueId;
	
	@Column(name = "TASKUID")
	protected String operationTaskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
	protected OperationTask operationTask;

	/**
	 * 类型与状态映射--assntype
	 */
	@Column(name = "ASSNTYPE")
	protected Integer assnType;
//	// many-to-one
//	@ForeignKey(name = "null")
//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumnsOrFormulas(value = {
//			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
//			@JoinColumnOrFormula(formula = @JoinFormula(value = "'assntype'", referencedColumnName = "TYPESNAME")) })
//	protected TypesData assnTypeDesc;

	@Column(name = "ASSNSTART")
	protected Date assnStart;
	@Column(name = "ASSNFINISH")
	protected Date assnFinish;
	@Column(name = "ASSNQTY")
	protected Double assnQty;
	
	/**
	 * 分派单元数，可以为百分比
	 */
	@Column(name = "ASSNUNITS")
	protected Integer reqQty;
	/**
	 * 类型与状态映射--assnstate
	 */
	@Column(name = "ASSNSTATE")
	protected Integer assnState;
//	// many-to-one
//	@ForeignKey(name = "null")
//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumnsOrFormulas(value = {
//			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
//			@JoinColumnOrFormula(formula = @JoinFormula(value = "'assnstate'", referencedColumnName = "TYPESNAME")) })
//	protected TypesData assnStateDesc;
	
	/**
	 * 是否有效
	 */
	@Column(name = "ISINEFFECT")
	protected Boolean effective;
	
	@Column(name = "RESUID")
	protected String resourceUid;	
	
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RESUID", insertable = false, updatable = false)
	protected Part resource;

	
	/**
	 * 空的构造函数
	 */
	public TaskResource() {
		this.setAssnType(Assignment.ASSNTYPE_WORKCENTER);
	}
	
	/**
	 * 获取资源的物料Uid
	 * @return
	 */
	
	public String getResourceUid() {
		return resourceUid;
	}
	/**
	 * 设置资源的物料Uid
	 * @param resourceItemUid
	 */
	public void setResourceUid(String resourceUid) {
		this.resourceUid = resourceUid;
	}
	/**
	 * 获取资源
	 * @return
	 */
	
	public Part getResource() {
		return resource;
	}
	/**
	 * 设置资源
	 * @param resource
	 */
	public void setResource(Part resource) {
		this.resource = resource;
	}

	public OperationTask getOperationTask() {
		return operationTask;
	}

	public void setOperationTask(OperationTask operationTask) {
		this.operationTask = operationTask;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}
	
	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getOperationTaskUid() {
		return operationTaskUid;
	}

	public void setOperationTaskUid(String operationTaskUid) {
		this.operationTaskUid = operationTaskUid;
	}

	public Integer getAssnType() {
		return assnType;
	}

	public void setAssnType(Integer assnType) {
		this.assnType = assnType;
	}

	public Date getAssnStart() {
		return assnStart;
	}

	public void setAssnStart(Date assnStart) {
		this.assnStart = assnStart;
	}

	public Date getAssnFinish() {
		return assnFinish;
	}

	public void setAssnFinish(Date assnFinish) {
		this.assnFinish = assnFinish;
	}

	public Double getAssnQty() {
		return assnQty;
	}

	public void setAssnQty(Double assnQty) {
		this.assnQty = assnQty;
	}

	public Integer getReqQty() {
		return reqQty;
	}

	public void setReqQty(Integer reqQty) {
		this.reqQty = reqQty;
	}

	public Integer getAssnState() {
		return assnState;
	}

	public void setAssnState(Integer assnState) {
		this.assnState = assnState;
	}

	public Boolean getEffective() {
		return effective;
	}

	public void setEffective(Boolean effective) {
		this.effective = effective;
	}
	
}
